/*
 * Name: Minh-Tuan ta
 */

package data;

import java.util.ArrayList;

import beans.Comment;
import beans.Content;
import beans.Post;

/*
 * Author: Minh-Tuan Ta
 * Date: 11/6/11
 * Class: StatusDB
 * This class is the data access class for status
 */
public class CommentDB extends ContentDB {
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getComments
	 * This method will get all the comments in the database
	 */
	public static synchronized ArrayList<Comment> getComments()
	{
		return convertContentsToComments(getAllContentOfContenttype(ContentTypeDB.getContentTypeID("Comment")));
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getCommentsOfUser
	 * This method will get all the comments of a specific user in the database
	 */
	public static synchronized ArrayList<Comment> getCommentsOfUser(int userid)
	{
		return convertContentsToComments(getContentsOfUserAndType(userid, ContentTypeDB.getContentTypeID("Comment")));
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getCommentsToContent
	 * This method will get all the comments on a content in the database
	 */
	public static synchronized ArrayList<Comment> getCommentsForContent(int contentid)
	{
		ArrayList<Comment> comments = new ArrayList<Comment>();
		ArrayList<Content> contents = getContentOfExtraAndType(contentid, ContentTypeDB.getContentTypeID("Comment"));
		
		for (int i = 0; i < contents.size(); i++)
		{
			comments.add(convertContentToComment(contents.get(i)));
		}

		return comments;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: addComment
	 * This method will add a new comment
	 */
	public static synchronized int addComment(Content comment)
	{
		return addContent(comment);
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: deleteComment
	 * This method will delete a comment
	 */
	public static synchronized int deleteComment(Content comment)
	{
		return deleteContent(comment);
	}
}
